package scala.Implicit.Conversion

class Complex(val real: Double, val img: Double) {
   def +(that: Complex): Complex = {
      new Complex(this.real + that.real, this.img + that.img)
   }

   def -(that: Complex): Complex = {
      new Complex(this.real - that.real, this.img - that.img)
   }

   def ~ : Double = {
      Math.sqrt(real * real + img * img)
   }

   override def toString() = {
      if (img > 0)
         real + "+" + img + "i"
      else if (img == 0)
         real.toString()
      else
         real + " " + img + "i"
   }
}